<!DOCTYPE html>
<html>

	<head>
		<title>多彩蓓蕾</title>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
		<meta name="description" content=" ">
		<link rel="stylesheet" href="lib/weui.min.css">
		<link rel="stylesheet" href="css/jquery-weui.css">
		<link rel="stylesheet" href="css/style.css" />

	</head>
	<style>

	</style>

	<body ontouchstart>
		<div class="news">
			
			<div class="weui-loadmore" jiazai="1">
				<i class="weui-loading"></i>
				<span class="weui-loadmore__tips">正在加载</span>
			</div>
		</div>
		<div class="clear"></div>
		

		<script src="lib/jquery-2.1.4.js"></script>

		<script src="https://cdn.bootcss.com/jquery_lazyload/1.9.7/jquery.lazyload.js"></script>
		<script src="js/jquery-weui.js"></script>
		<script src="lib/fastclick.js"></script>
		<script>
			//图片懒加载
			$("img.lazy").lazyload({
				placeholder: "img/pic_article.png",
				threshold: 200,
				event: 'scroll',
				//failurelimit : 10 ,
				effect: "fadeIn"
			});

			$(function() {
				//处理屏幕点击延迟
				FastClick.attach(document.body);
				//page初始化 为1
				var sb = 1;
				//状态标记
				var loading = false;
				//上拉加载 函数启动

				$(document.body).infinite().on("infinite", function() {
					if(loading) return;
					loading = true;
					sb++;
					//分页触底 停止上拉加载
					if($('.weui-loadmore').attr('jiazai') == 0) {
						return false;
					}

					$.ajax({
						type: 'GET',
						url: 'http://cf.588net.com/index.php/api/Article/getList?page=' + sb,

						dataType: 'json',
						success: function(e) {
							//alert(e.data);
							
							var html = '';
							//var date = $('.news h3').text();
							
							//console.log(e.data.length);
							if(e.data.length == 0) {
								$('.weui-loadmore__tips').text('已经到底了哟！');
								$('.weui-loading').hide();
								$('.weui-loadmore').attr('jiazai', 0);
								return false;
							}
							
							if(e.code == 200) {
								//console.log(date);

								$.each(e.data, function(a, b) {
										var ss = window.localStorage.getItem('dates');
										//var sa = localStorage.getItem("dates");
										//console.log(sa);
										//alert(sa);
										//alert(date);
										if(ss == a) {
//											//alert(typeof(date));
//											var log = $('.news-box h3').text();
//											var str = JSON.stringify(log);
//											
											$.each(b, function(c, d) {
												//console.log(d);
												html += '<div class="news-list">';
												html += '<a href="news.html">';
												html += '<div class="new-text">';
												html += '<p class="news-info">' + d.title + '</p>';
												html += '<p class="review">' + d.username + '<span>' + '阅读数' + d.view + '</span></p></div>';
												html += '<div class="news-img">';
												html += '<img class="lazy" data-original="' + d.cover + '">';
												html += '</div>';
												html += '</a>';
												html += '</div>';
											})

											//$('.news-list:last-of-type').append(html)
											//$(html).insertAfter('.news-list:last-of-type')

										} else {
											html += '<div class="news-box">';
											html += '<h3 data-id="' + a + '">' + a + '</h3>';
											$.each(b, function(c, d) {
												//console.log(d);
												html += '<div class="news-list">';
												html += '<a href="news.html">';
												html += '<div class="new-text">';
												html += '<p class="news-info">' + d.title + '</p>';
												html += '<p class="review">' + d.username + '<span>' + '阅读数' + d.view + '</span></p></div>';
												html += '<div class="news-img">';
												html += '<img class="lazy" data-original="' + d.cover + '">';
												html += '</div>';
												html += '</a>';
												html += '</div>';
											})
											html += '</div>';
											loading = false;
											$(html).insertBefore('.weui-loadmore');

										}
										window.localStorage.setItem('dates', a);
										//html+='';
									})
									//alert('ok')

								$("img.lazy").lazyload({
									placeholder: "img/pic_article.png",
									threshold: 200,
									event: 'scroll',
									//failurelimit : 10 ,
									effect: "fadeIn"
								});

							}
						}
					})

				});
				//默认地一页
				$.ajax({
					//crossOrigin: true,
					//async: false,
					type: 'GET',
					url: 'http://cf.588net.com/index.php/api/Article/getList?page=1',

					dataType: 'json',
					success: function(e) {
						//alert(8888)
						var html = '';
						//var date=$('.news h3').text();
						//console.log(e.data);
						//console.log(e.data);
						if(e.code == 200) {
							
							//console.log(date);
							$.each(e.data, function(a, b) {
									window.localStorage.setItem('dates', a);
									//console.log(a);
									html += '<div class="news-box">';
									html += '<h3 data-id="' + a + '">' + a + '</h3>';
									$.each(b, function(c, d) {
										//console.log(d);
										html += '<div class="news-list">';
										html += '<a href="news.html">';
										html += '<div class="new-text">';
										html += '<p class="news-info">' + d.title + '</p>';
										html += '<p class="review">' + d.username + '<span>' + '阅读数' + d.view + '</span></p></div>';
										html += '<div class="news-img">';
										html += '<img class="lazy" data-original="' + d.cover + '">';
										html += '</div>';
										html += '</a>';
										html += '</div>';
									})
									html += '</div>';
									//html+='';
							})								
							$(html).insertBefore('.weui-loadmore');
							$("img.lazy").lazyload({
								placeholder: "img/pic_article.png",
								threshold: 200,
								event: 'scroll',
								//failurelimit : 10 ,
								effect: "fadeIn"
							});

						}
					}
				})

			})
		</script>

	</body>

</html>